using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Flan.Controls;

/// <summary>
/// Same concept as example 04. In addition, we are Updating UpdatePanel1 when 
/// the DetailsView1 ItemUpdate event fires. We also switch to ReadOnly mode anytime the select event fires.
/// </summary>
public partial class _05_Master_Details_With_Edit : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {
        System.Threading.Thread.Sleep(200);
        UpdatePanelPopupExtender.RegisterCloseControl(divClose, UpdatePanel2);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
        if (e.CommandName != "Select") {
            UpdatePanel1.Update();
        }
        else {
            DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
            Control c = e.CommandSource as Control;
            if (c != null) {
                UpdatePanelPopupExtender2.ShowAt(c);
            }
        }
    }
    
    protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) {
        GridView1.DataBind();
        UpdatePanel1.Update();
    }
    protected void UpdatePanelPopupExtender2_Close(object sender, EventArgs e)
    {
        GridView1.SelectedIndex = -1;
        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
    }
}
